<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>product</title>
    <script type="text/javascript" src="../frame/assets/js/lib/jquery.min.js"></script>
	<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
	<script src="../frame/layui/lay/modules/layer.js"></script>
    <link rel="stylesheet" href="../frame/layui/lay/modules/layer/default/layer.css">
    <link rel="stylesheet" href="../frame/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../frame/assets/css/lib/bootstrap.min.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/font-awesome.min.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/themify-icons.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/unix.css">
    <link rel="stylesheet" href="../frame/assets/css/style.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/menubar/sidebar.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/sweetalert/sweetalert.css">
</head>
<body>
<div class="content-wrap">
    <div class="main">
        <div class="container-fluid" >
            <!--欢迎栏-->
            <div class="row" >
                <div class="col-lg-8 p-r-0 title-margin-right">
                    <div class="page-header">
                        <div class="page-title" >
                            <h1>资产统计</h1>
                        </div>
                    </div>
                </div>
             </div>
             	<h5>最右端置有按钮---可编辑 可删除</h5>
				<table id="demo" lay-filter="test"></table>
				<br><br>

            
            <div class="row">
                  <div class="col-md-3">
                  		
                        <button type="button" class="layui-btn" onclick="all1()">
                        <i class="layui-icon layui-icon-template-1"></i>
                        	显示资产总量<br>
                        	<div id="mydiv1" style="text-alien:center"></div>
                        </button>        
                                 
                    </div>
                    <div class="col-md-3">
                       <button type="button" class="layui-btn layui-btn-warm" onclick="all2()">
                       <i class="layui-icon layui-icon-rmb"></i>
                       		显示资产总额
                       	<div id="mydiv2" style="text-alien:center"></div>
                       	</button>
                                     
                                   
                    </div>
                    <div class="col-md-3" >
                       
                            <button type="button" class="layui-btn layui-btn-normal" onclick="all3()">
                            <i class="layui-icon layui-icon-util"></i>	
                            	显示已在处置
                            <div id="mydiv3" style="text-alien:center"></div>
                            </button>           
                            
                                    
                    </div>
            </div>
        </div>  
    </div>
</div>
<!--搜索-->
<div id="search">
    <button type="button" class="close">×</button>
    <form>
        <input type="search" value="" placeholder="type keyword(s) here" />
        <button type="submit" class="btn btn-primary">Search</button>
    </form>
</div>
<script type="text/html" id="barDemo">
 <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
 <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>      	
</script>

<script src="../frame/assets/js/lib/jquery.min.js"></script>
<script src="../frame/assets/js/lib/jquery.nanoscroller.min.js"></script>
<script src="../frame/assets/js/lib/menubar/sidebar.js"></script>
<script src="../frame/assets/js/lib/bootstrap.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/datatables.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/dataTables.buttons.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.flash.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/jszip.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/pdfmake.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/vfs_fonts.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.html5.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.print.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/datatables-init2.js"></script>
<script src="../frame/assets/js/lib/sweetalert/sweetalert.min.js"></script>
<script src="../frame/assets/js/lib/sweetalert/zhuxiao.js"></script>
<script type="text/javascript" src="../frame/layui/layui.js" charset="utf-8"></script>
<script>
layui.use('table', function(){
  var table = layui.table;
  
  //第一个实例
  table.render({
    elem: '#demo'
    ,height: '450px'
    ,url: 'selectallproduct' //数据接口
    ,method:'get'
    ,page: true //开启分页
    ,cols: [[ //表头
      {field:'id', width:90, title: 'ID编号', sort: true,fixed:'left'}
      ,{field:'zcid', width:130, title: '资产编码',sort:true}
      ,{field:'zcname', width:130, title: '资产名称'}
      ,{field:'money', width:130, title: '资产金额(元)',sort:true}
      ,{field:'zcclass', width:150, title: '资产大类'}
      ,{field:'zcperson', width:120, title: '审核人'}
      ,{field:'begint',width:120, title: '购置日期', sort: true}
      ,{field:'right', width:120, title: '操作',toolbar:'#barDemo'}
    ]]
  });
  //监听行事件
  table.on('tool(test)', function(obj){
	var data = obj.data;var id=data.id;var zcid=data.zcid;
    if(obj.event === 'del'){
      layer.confirm('真的删除行么',{btn:['删除','撤销']}
   		 ,function(index)
   		 {
     		 obj.del();
     		 deletebyid(data.id);
          layer.close(index);
   		 })
      	
    } else if(obj.event === 'edit'){
		//实现编辑
		layer.open({
			type:2
			,title:"编辑资产信息"
			,content:'editproduct.html'
			,maxmin:true
			,area:['700px']['600px']
			,btn:['确认','撤销']
			,yes:function(index,layero){
				//回调的数值,取输入框的内容
				var id=$(layero).find('iframe')[0].contentWindow.id.value;	
				var zcid=$(layero).find('iframe')[0].contentWindow.zcid.value;
				var zcname=$(layero).find('iframe')[0].contentWindow.zcname.value;
				var money=$(layero).find('iframe')[0].contentWindow.money.value;
				var zcclass=$(layero).find('iframe')[0].contentWindow.zcclass.value;
				var zcperson=$(layero).find('iframe')[0].contentWindow.zcperson.value;
				var begint=$(layero).find('iframe')[0].contentWindow.begint.value;
				//同步数据表格
				obj.update({
					'id':id,
					'zcid':zcid,
					'zcname':zcname,
					'money':money,
					'zcclass':zcclass,
					'zcperson':zcperson,
					'begint':begint
				})
				
			     $.ajax({
					url:'editproduct?id='+id+"&zcid="+zcid+"&zcname="+zcname+"&money="+money+"&zcclass="+zcclass+"&zcperson="+zcperson+"&begint="+begint ,
					type:'post',
					contentType:'application/json;charset=utf-8',
					dataType:'text',
					data:{
						'id':id,
						'zcid':zcid,
						'zcname':zcname,
						'money':money,
						'zcclass':zcclass,
						'zcperson':zcperson,
						'begint':begint
					},
					success:function(res){
						layer.msg("编辑成功");
					},
					error:function(res){
						layer.msg("编辑失败！");
					}
				})
				layer.close(index);
			 }
			,success:function(layero,index){
				var div=layero.find('iframe').contents().find('#useradmin');
				var body=layer.getChildFrame('body',index);
				var iframeWindow=window['layui-layer-iframe'+index]
				body.find('#id').val(data.id);
				body.find('#zcid').val(data.zcid);
				body.find('#zcname').val(data.zcname);
				body.find('#money').val(data.money);
				body.find('#zcclass').val(data.zcclass);
				body.find('#zcperson').val(data.zcperson);
				body.find('#begint').val(data.begint);
			}
		})
     }//编辑完成
     
   });
 });
 
 function deletebyid(index){
	 var id=index;
	console.log(id);
	 $.ajax({
		 type:"post",
		 url:'delproduct',
		 data:{'id':id},
		 dataType:'text',
		 success:function(res){
			 alert("成功");
		 },
		 error:function(XMLHttpRequest,textStatus,errorThrown){
			 alert(typeof(errorThrown));
		 }
	 });
 }

function all1(){
 	 $.ajax({
 		 type:"post",
 		 url:'allp1',
 		 data:{'data':1},
 		 dataType:'text',
 		 success:function(data){
 			 //alert(data);
 			 document.getElementById("mydiv1").innerHTML=data;
 		 },
 		 error:function(XMLHttpRequest,textStatus,errorThrown){
 			 
 			 alert(typeof(errorThrown)+"00");
 		 }
 	 });
}
function all2(){
	 $.ajax({
		 type:"post",
		 url:'allp2',
		 data:{'data':2},
		 dataType:'text',
		 success:function(data){
			
			 document.getElementById("mydiv2").innerHTML=data;
		 },
		 error:function(XMLHttpRequest,textStatus,errorThrown){
			 
			 alert(typeof(errorThrown)+"00");
		 }
	 });
}
function all3(){
	 $.ajax({
		 type:"post",
		 url:'allp3',
		 data:{'data':3},
		 dataType:'text',
		 success:function(data){
			 
			 document.getElementById("mydiv3").innerHTML=data;
		 },
		 error:function(XMLHttpRequest,textStatus,errorThrown){
			 
			 alert(typeof(errorThrown)+"00");
		 }
	 });
}
</script>
</body>
</html>